package com.aiwei.tdjk.service.impl;

import com.aiwei.tdjk.bean.Pager;
import com.aiwei.tdjk.dao.extend.CustomsStandardExtendMapper;
import com.aiwei.tdjk.dto.request.CustomsStandardPagerRequest;
import com.aiwei.tdjk.entity.CustomsStandard;
import com.aiwei.tdjk.entity.CustomsStandardExample;
import com.aiwei.tdjk.service.CustomsStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomsStandardServiceImpl implements CustomsStandardService{

    @Autowired
    private CustomsStandardExtendMapper customsStandardExtendMapper;


    /**
     * 分页查询
     * @param request
     * @return
     */
    @Override
    public Pager<CustomsStandard> find(CustomsStandardPagerRequest request) {
        request.webParamConvert();
        List<CustomsStandard> list = customsStandardExtendMapper.find(request);
        int totalCount = customsStandardExtendMapper.getTotalCount(request);
        Pager<CustomsStandard> pager = new Pager<>();
        pager.setPageNumber(request.getPageNumber());
        pager.setPageSize(request.getPageSize());
        pager.setList(list);
        pager.setTotalCount(totalCount);
        return pager;
    }


    /**
     * 获取
     * @param id
     * @return
     */
    @Override
    public CustomsStandard get(Long id){
        return customsStandardExtendMapper.selectByPrimaryKey(id);
    }

    @Override
    public CustomsStandard getByStandard(String standard) {
        CustomsStandardExample example = new CustomsStandardExample();
        example.or().andStandardEqualTo(standard);
        List<CustomsStandard> customsStandards = customsStandardExtendMapper.selectByExample(example);
        if (customsStandards!=null&customsStandards.size()>0){
            return customsStandards.get(0);
        }
        return null;
    }


    /**
     * 新增
     *
     * @param customsStandard
     * @return
     */
    @Override
    public int add(CustomsStandard customsStandard) {
        return customsStandardExtendMapper.insertSelective(customsStandard);
    }

    /**
     * 更新
     *
     * @param customsStandard
     */
    @Override
    public void update(CustomsStandard customsStandard) {
        customsStandardExtendMapper.updateByPrimaryKeySelective(customsStandard);
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void delete(Long id) {
        customsStandardExtendMapper.deleteByPrimaryKey(id);
    }

}
